using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPColorsService
    {
        ISession session;

        public MRPColorsService(ISession session)
        {
            this.session = session;
        }
        public MRPColorsService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpcolors(MRPColors mrpcolorsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpcolorsX);
            tx.Commit();
        }

        public void UpdateMrpcolors(MRPColors mrpcolorsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpcolorsX);
            tx.Commit();
        }

        public void DeleteMrpcolors(MRPColors mrpcolorsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpcolorsX);
            tx.Commit();
        }

        public IList<MRPColors> GetAllMrpcolors(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPColors");
            IList<MRPColors> list = query.List<MRPColors>();
            if (evict)
            {
                foreach (MRPColors s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPColors GetAllMrpcolorsByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPColors as c where c.Colorcode= :x");
            query.SetString("x", id);
            MRPColors s = (MRPColors)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPColors> GetMrpcolorsByQuery(IQuery query, Boolean evict)
        {
            IList<MRPColors> list = query.List<MRPColors>();
            if (evict)
            {
                foreach (MRPColors s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }


    }
}
